package com.tepth.appmanageservice.protocol.bodys.ordinaryfile;

import com.tepth.appmanageservice.protocol.Index;
import com.tepth.appmanageservice.protocol.interfaces.IReceive;
import com.tepth.appmanageservice.tools.ext.ExtToBytes;
import com.tepth.appmanageservice.tools.ext.ExtToInt;
import com.tepth.appmanageservice.tools.ext.ExtToString;

public class OrdinaryFileIssued implements IReceive {
	public static final short ID = 0x0E22;

	private byte fileType;// �ļ�����
	private byte fileNameLen;// �ļ�������(N)
	private String fileName;// �ļ���
	private int fileLen; // �ļ���С
	private String md5; // MD5ֵ
	private short packetCount; // �ļ��ܰ���

	public byte getFileType() {
		return this.fileType;
	}

	public void setFileType(byte fileType) {
		this.fileType = fileType;
	}

	public byte getFileNameLen() {
		return this.fileNameLen;
	}

	public void setFileNameLen(byte fileNameLen) {
		this.fileNameLen = fileNameLen;
	}

	public String getFileName() {
		return this.fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public int getFileLen() {
		return this.fileLen;
	}

	public void setFileLen(int fileLen) {
		this.fileLen = fileLen;
	}

	public String getMd5() {
		return this.md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public short getPacketCount() {
		return this.packetCount;
	}

	public void setPacketCount(short packetCount) {
		this.packetCount = packetCount;
	}

	@Override
	public short getLength() {
		return 0;
	}

	@Override
	public void setLength(int length) {

	}

	@Override
	public void Receive(byte[] data, Index index) {
		this.fileType = data[index.get()];
		this.fileNameLen = data[index.get()];

		byte[] docNameBytes = ExtToBytes.fromByteArray(data, index, this.fileNameLen);
		this.fileName = new String(docNameBytes);

		this.fileLen = ExtToInt.fromByteArrayTo32(data, index);
		byte[] md5Bytes = ExtToBytes.fromByteArray(data, index, 16);
		this.md5 = ExtToString.fromByteArrayForHex(md5Bytes);

		this.packetCount = ExtToInt.fromByteArrayTo16(data, index);
	}
}